﻿using System.Collections.Generic;
using UnityEngine;

public class GameRes
{
	public static GameRes Ins = new GameRes();

	public GameObject ImageItem;
	public GameObject FireMiddle;
	public GameObject FireRight;

	private Dictionary<string, Sprite> spriteDic = new Dictionary<string, Sprite>();

	public void Awake()
	{
		Ins = this;
	}

	public void Load()
	{
		ImageItem = Resources.Load<GameObject>("Prefabs/ImageItem");
		FireMiddle = Resources.Load<GameObject>("Bomb/Prefabs/Fire_Middle");
		FireRight = Resources.Load<GameObject>("Bomb/Prefabs/Fire");
	}

	public GameObject InstantiateImageItem()
	{
		GameObject go = null;
		if (ImageItem)
		{
			go = GameObject.Instantiate(ImageItem);
		}
		return go;
	}

	public Sprite LoadSprite(string name, string parent = "")
	{
		if (string.IsNullOrEmpty(parent))
		{
			if (!spriteDic.ContainsKey(name))
			{
				spriteDic.Add(name, Resources.Load<Sprite>(name));
			}
		}
		else
		{
			if (!spriteDic.ContainsKey(name))
			{
				Sprite[] sprites = Resources.LoadAll<Sprite>(parent);
				for (int i = 0, length = sprites.Length; i < length; i++)
				{
					Sprite sprite = sprites[i];
					if (!spriteDic.ContainsKey(sprite.name))
					{
						spriteDic.Add(sprite.name, sprite);
					}
				}
			}

		}

		return spriteDic[name];
	}
}
